<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
<!--
  Content-Type: multipart/form-data
-->
<!--<script>
  const str = `# Marked in the browser\n\nRendered by
**marked**

\`aaa\`

## h2 title

你@-_%^&

>引用:xxxxx

\`\`\`html
<a class="a123">我是a标签</a>
<p>我是p标签</p>
\`\`\`

\`\`\`js
let a = 123;
console.log(a);
function abc(){}
class bb{}
for(let i=0;i<3;++i){
    console.log(i)
}
console.log(a)
const a = require('hightlight.js')
\`\`\`

\`\`\`css
a {
  color:red;
  background: url("./1.png");
}
\`\`\`

![](./01.jpg)
![](./02.jpg)

+ Create a list by starting a line with \`+\`, \`-\`, or \`*\`
+ Sub-lists are made by indenting 2 spaces:
  - Marker character change forces new list start:
    * Ac tristique libero volutpat at
    + Facilisis in pretium nisl aliquet
    - Nulla volutpat aliquam velit
+ Very easy!

> Blockquotes can also be nested...
>> ...by using additional greater-than signs right next to each other...
> > > ...or with spaces between arrows.

> Classic markup: :wink: :crush: :cry: :tear: :laughing: :yum:
>
> Shortcuts (emoticons): :-) :-( 8-) ;)

::: warning
warning container
:::

| Option | Description |
| &#45;&#45;&#45;&#45;&#45;&#45; | -&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45; |
| data   | path to data files to supply the data that will be passed into templates. |
| engine | engine to be used for processing templates. Handlebars is the default. |
| ext    | extension to be used for dest files. |`;
  const formData = new FormData();
  formData.append('md', str);
  formData.append('other1', 1);
  formData.append('other2', '2');
  const xhr = new XMLHttpRequest();
  xhr.open('POST', '/v1/test-multer/textfields');
  // xhr.responseType = 'json';
  // xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  //默认如果xhr发送的是formData类型 则Content-Type会自动置为 multipart/form-data

  xhr.onreadystatechange = function () {
    if (xhr.readyState === 4 && xhr.status === 200) {
      console.log(typeof xhr.response);
      console.log(xhr.response);
      console.log(typeof xhr.responseText);
      console.log(xhr.responseText);
    }
  };

  xhr.send(formData);
</script>-->

<!--
  form
-->
<!--<form action="/v1/test-form/1" method="post" enctype="application/x-www-form-urlencoded">
  <input type="text" name="username" placeholder="username"/>
  <input type="password" name="password" placeholder="password"/>
  <button>提交</button>
</form>-->

<!--
  application/x-www-form-urlencoded
-->
<!--<script>
  var data = "username=ahhh&password=123456";

  var xhr = new XMLHttpRequest();
  xhr.withCredentials = true;

  xhr.addEventListener("readystatechange", function() {
    if(this.readyState === 4) {
      console.log(this.responseText);
    }
  });

  xhr.open("POST", "http://localhost:3000/v1/test-form/1");
  xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

  xhr.send(data);
</script>-->

<script>

  var xhr = new XMLHttpRequest();
  xhr.withCredentials = true;
  xhr.responseType = 'json';

  xhr.addEventListener("readystatechange", function () {
    if (this.readyState === 4) {
      // console.log(this.responseText); //Uncaught DOMException: Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'json')
      console.log(this.response);
      const date = new Date(this.response.data.createdAt);
      console.log(date.getHours());
      console.log(date.getMinutes());
      console.log(date.getSeconds());
    }
  });

  xhr.open("GET", "http://localhost:3000/v1/article/4");

  xhr.send(null);
</script>
</body>
</html>
